
export default function verifyOrder(order, qt, data, auth) {
    let quantity

    if (!order) {
        quantity = auth.hasOwnProperty('Control_FirstStep')
            ? Math.floor(qt * auth['Control_FirstStep'])
            : qt

        return quantity
    }

    if (order.OrderName.includes('调机')) {
        const last = data[order.index - 1]
        quantity =
            last && last.ProduceStyle === 0 ? Number(last.GoodQty) : verifyOrder(last, qt, data, auth)
    }

    if (order.index === 0 && auth.hasOwnProperty('Control_FirstStep')) {
        quantity = Math.floor(qt * auth['Control_FirstStep'])
    } else if (order.index === 0) {
        quantity = qt
    }

    if (order.ProduceStyle === 1) {
        if (auth.hasOwnProperty('Control_WeiWai')) {
            quantity = Number(order.GoodQty)
        } else {
            const last = data[order.index - 1]
            quantity =
                last && last.ProduceStyle === 0 && !last.OrderName.includes('调机')
                    ? Number(last.GoodQty)
                    : verifyOrder(last, qt, data, auth)
        }
    } else {
        const last = data[order.index - 1]
        if (last) {
            if (last.OrderName.includes('调机') || last.ProduceStyle === 1) {
                quantity = verifyOrder(last, qt, data, auth)
            } else {
                quantity = last ? Number(last.GoodQty) : verifyOrder(last, qt, data, auth)
            }
        } else {
            quantity = auth.hasOwnProperty('Control_FirstStep')
                ? Math.floor(qt * auth['Control_FirstStep'])
                : qt
        }
    }

    return quantity
}

